package com.wgts.wgts.mvp.view.activity.bootpage;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.wgts.wgts.AppConstant;
import com.wgts.wgts.R;
import com.wgts.wgts.control.dialog.WonderLoadingDialog;
import com.wgts.wgts.mvp.view.activity.main.MoHuMainActivity;
import com.wgts.wgts.tools.AppInfor;
import com.wgts.wgts.tools.SharedpreferencesHelper;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class BootPageFragment extends Fragment {

    @BindView(R.id.img_boot)
    ImageView imgBoot;
    Unbinder unbinder;
    @BindView(R.id.linear_ensur)
    LinearLayout linearEnsur;
    private int resourceId;

   private  WonderLoadingDialog wonderLoadingDialog = null;
    private static final String RESOURCEID = "RESOURCEID";


    public static BootPageFragment getInstance(int resourceId) {
        BootPageFragment fragment = new BootPageFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(RESOURCEID, resourceId);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        wonderLoadingDialog = new WonderLoadingDialog(getActivity());
        resourceId = getArguments().getInt(RESOURCEID);
        View view = inflater.inflate(R.layout.boot_page_fragment, container, false);
        unbinder = ButterKnife.bind(this, view);
        initView();
        return view;
    }

    private void initView() {
        imgBoot.setImageResource(resourceId);
        if(resourceId == R.mipmap.boot_three){
            linearEnsur.setVisibility(View.VISIBLE);
        }else{
            linearEnsur.setVisibility(View.GONE);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick(R.id.linear_ensur)
    public void onViewClicked() {
        if(wonderLoadingDialog != null){
            wonderLoadingDialog.show();
        }
        SharedpreferencesHelper.getInstance().write(AppConstant.SHARED_VERSION, AppInfor.getInstance().getAppVersionCode());
        Intent intent = new Intent(getContext(), MoHuMainActivity.class);
        startActivity(intent);
        getActivity().finish();
    }
}
